Overview
DevolutionSync uses MySQL 8.0 as its relational database system. The schema is designed to handle product returns, deviations, user management, and audit trails with proper normalization and referential integrity.Database Information
Database Name
devolutionsyncCharacter Set
utf8Tables
5 tables
Entity Relationship Overview
Table Definitions
devoluciones
Core table storing all product return and deviation records.Script_DB.sql
Field Descriptions
Customer Information
Customer Information
| Field | Type | Description |
|---|---|---|
nit | VARCHAR(20) | Customer tax identification number |
nombre_cliente | VARCHAR(255) | Customer full name |
direccion | TEXT | Customer delivery address |
Product Information
Product Information
| Field | Type | Description |
|---|---|---|
codigo_producto | VARCHAR(50) | Product SKU/code |
descripcion_producto | TEXT | Product description |
unidad | VARCHAR(20) | Unit of measure (e.g., “UND”, “KG”) |
kg | DECIMAL(10,2) | Product weight in kilograms |
Deviation Details
Deviation Details
| Field | Type | Description |
|---|---|---|
motivo | ENUM | Reason: devolucion, faltante, sobrante |
cantidad_und | INT | Quantity in units |
cantidad_kg | DECIMAL(10,2) | Quantity in kilograms |
evidencia | VARCHAR(255) | File path to uploaded evidence |
observacion | TEXT | Initial observations from creator |
Review Information
Review Information
| Field | Type | Description |
|---|---|---|
estado | ENUM | Status: pendiente, aprobado, rechazado |
observacion_admin | TEXT | Administrator’s review comments |
codigo_admin | VARCHAR(50) | Authorization code from admin |
usuario_revisor | VARCHAR(50) | Username who reviewed (FK to usuarios) |
fecha_revision | TIMESTAMP | Date/time of review |
Audit Trail
Audit Trail
| Field | Type | Description |
|---|---|---|
id | INT | Auto-increment primary key |
fecha_creacion | TIMESTAMP | Automatic creation timestamp |
usuario_creador | VARCHAR(50) | Username who created record (FK to usuarios) |
Estado Enum Values
Motivo Enum Values
- devolucion
- faltante
- sobrante
Product Return: Customer returning product due to defects, quality issues, or order errors.Common scenarios:
- Damaged goods
- Wrong product delivered
- Quality not meeting specifications
usuarios
User authentication and role management table.Script_DB.sql
Field Descriptions
| Field | Type | Description |
|---|---|---|
USR | VARCHAR(50) | Username (Primary Key) |
PAS | VARCHAR(50) | Password (plaintext - should be hashed in production) |
NOMBRE | VARCHAR(100) | Full name of user |
GRADO | INT | Role level: 1=Admin, 2=Auxiliary, 3=Consultant |
User Roles (GRADO)
Administrator
GRADO = 1
- Review deviations
- Approve/reject requests
- View all records
- Access dashboard
Auxiliary
GRADO = 2
- Create deviations
- Upload evidence
- View own records
- Limited access
Consultant
GRADO = 3
- Read-only access
- View history
- Search records
- No modifications
Sample Data
Script_DB.sql
notificaciones
Notification system for user alerts and status updates.Script_DB.sql
Field Descriptions
| Field | Type | Description |
|---|---|---|
id | INT | Auto-increment primary key |
id_devolucion | INT | Foreign key to devoluciones table |
mensaje | TEXT | Notification message content |
leida | BOOLEAN | Read status (FALSE = unread) |
fecha | TIMESTAMP | Notification creation timestamp |
usuario_destino | VARCHAR(50) | Target user (FK to usuarios.USR) |
Foreign Key Relationship
Notifications are automatically created when:
- Administrator approves a deviation
- Administrator rejects a deviation
- Status changes require user attention
login_attempts
Security table tracking failed login attempts for brute-force protection.Script_DB.sql
Field Descriptions
| Field | Type | Description |
|---|---|---|
id | INT | Auto-increment primary key |
ip_address | VARCHAR(45) | Client IP address (supports IPv6) |
username | VARCHAR(50) | Attempted username |
attempts | INT | Number of failed attempts |
last_attempt | DATETIME | Timestamp of most recent attempt |
created_at | TIMESTAMP | First attempt timestamp |
Security Features
producto
Product catalog with item codes, descriptions, and specifications.Script_DB.sql
Field Descriptions
| Field | Type | Description |
|---|---|---|
id | INT(11) | Auto-increment primary key |
item | INT(11) | Product item code/SKU |
descripcion | VARCHAR(50) | Product description |
minimo | FLOAT | Minimum acceptable weight |
maximo | FLOAT | Maximum acceptable weight |
pesoProm | FLOAT | Average/standard weight |
Sample Data
Script_DB.sql
The
minimo, maximo, and pesoProm fields are used for weight validation when creating deviations. They help identify if reported quantities fall within acceptable ranges.Indexes and Constraints
Primary Keys
devoluciones.id- Auto-increment integerusuarios.USR- Varchar usernamenotificaciones.id- Auto-increment integerlogin_attempts.id- Auto-increment integerproducto.id- Integer
Foreign Keys
Recommended Indexes
Performance Indexes
Data Types and Constraints
Decimal Precision
DECIMAL(10,2) provides exact precision for financial and weight calculations, avoiding floating-point rounding errors.Timestamp Behavior
fecha_creacion: Automatically set on INSERTfecha_revision: NULL until admin reviews record
ENUM Constraints
- estado
- motivo
Query Examples
Common Queries
Database Setup
Initial Setup
Connection from PHP
Migration Considerations
Next Steps
MVC Structure
Learn how models interact with this schema
Architecture
Understand overall system design
API Reference
View model methods and database operations
Deployment
Deploy database with Docker